class ReunionsController < ApplicationController
  
  before_filter :login_required
  
  def index
    store_location
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    store_location
    @reunion_pages, @reunions = paginate :reunions, :per_page => 10
    
    @page, @lnk_from, @lnk_to = numeros_pagina @reunion_pages
  end

  def show
    store_location
    @reunion = Reunion.find(params[:id])
  end

  def new
    @reunion = Reunion.new
    # preseteo el alumno segun lo que llego por params
    if params[:reunion_alumno] != nil then 
      @reunion.persona_id = params[:reunion_alumno]
    end
  end

  def create
    @reunion = Reunion.new(params[:reunion])
    if @reunion.save
      flash[:success] = 'Reunion was successfully created.'
      redirect_back_or_default :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    @reunion = Reunion.find(params[:id])
  end

  def update
    @reunion = Reunion.find(params[:id])
    if @reunion.update_attributes(params[:reunion])
      flash[:success] = 'Reunion was successfully updated.'
      redirect_back_or_default :action => 'show', :id => @reunion
    else
      render :action => 'edit'
    end
  end

  def destroy
    Reunion.find(params[:id]).destroy
    redirect_back_or_default :action => 'list'
  end
end
